package com.byxy.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.byxy.dao.LyOrderDao;
import com.byxy.entity.LyOrder;
@Repository
public class LyOrderDaoImpl implements LyOrderDao {

	@Resource
	private SessionFactory sessionFactory;
	@Override
	public List<LyOrder> find() {
		
		return sessionFactory.getCurrentSession().createQuery("from Status").list();
	}

	@Override
	public void add(LyOrder a) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().save(a);
	}

	@Override
	public LyOrder getById(Integer id) {
		// TODO Auto-generated method stub
		return (LyOrder) sessionFactory.getCurrentSession().get(LyOrder.class, id);
	}

	@Override
	public void update(LyOrder a) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().update(a);
	}

	@Override
	public void deleteById(Integer id) {
		LyOrder a=new LyOrder();
		a.setId(id);
		sessionFactory.getCurrentSession().delete(a);
	}

	@Override
	public List<LyOrder> find(int curPage, int pageCount) {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from Status")
				.setFirstResult((curPage-1)*pageCount)
				.setMaxResults(pageCount)
				.list();
	}

	@Override
	public int count() {
		Long l=(Long) sessionFactory.getCurrentSession().createQuery("from Status").uniqueResult();
		return l.intValue();
	}

}
